﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Internal/Internal.Master" AutoEventWireup="true"
    CodeBehind="ERMgmt.aspx.cs" Inherits="Landscape.WebApp.Internal.ER.ERMgmt" Theme="Internal" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Src="../../Controls/Scribe.ascx" TagName="Scribe" TagPrefix="uc1" %>
<%@ Register Src="../../Controls/FileAttachments.ascx" TagName="FileAttachments"
    TagPrefix="uc2" %>
<%@ Register Assembly="Landscape.Web.Controls" Namespace="Landscape.Web.Controls" TagPrefix="cc1" %>
<%@ Register Src="../../Controls/EmergencyChat.ascx" TagName="EmergencyChat" TagPrefix="uc3" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" src="../../Scripts/ModuleMethods/ERManagement.js"></script>
    <script src="../../Scripts/OmniSignalR.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table style="height: 100%; width: 100%">
        <tr>
            <td style="height: 70px">
                <telerik:RadToolBar ID="rtbModuleActions" runat="server" Width="100%" OnClientButtonClicked="rtbModuleActions_OnClientButtonClicked"
                    EnableShadows="True">
                    <Items>
                        <telerik:RadToolBarButton runat="server" CommandName="LIST" ImageUrl="~/Images/Search.png"
                            Text="Search" CheckOnClick="True" ImagePosition="AboveText">
                        </telerik:RadToolBarButton>
                        <telerik:RadToolBarButton runat="server" CommandName="NEW" ImageUrl="~/Images/Write.png"
                            Text="New" CheckOnClick="True" ImagePosition="AboveText">
                        </telerik:RadToolBarButton>
                        <telerik:RadToolBarButton runat="server" CommandName="SAVE" ImageUrl="~/Images/Floppy.png"
                            Text="Save" CheckOnClick="True" ImagePosition="AboveText">
                        </telerik:RadToolBarButton>
                        <telerik:RadToolBarButton runat="server" CommandName="DELETE" ImageUrl="~/Images/Delete_32x32.png"
                            Text="Delete" CheckOnClick="True" ImagePosition="AboveText">
                        </telerik:RadToolBarButton>
                        <telerik:RadToolBarButton runat="server" IsSeparator="True" Text="Space">
                        </telerik:RadToolBarButton>
                    </Items>
                </telerik:RadToolBar>
            </td>
        </tr>
        <tr>
            <td style="vertical-align: top; height: 30px">
                <telerik:RadTabStrip ID="rtsERManagement" runat="server" MultiPageID="RadMultiPage1"
                    SelectedIndex="0" Width="100%" OnClientTabSelecting="rtsERManagement_OnClientTabSelecting">
                    <Tabs>
                        <telerik:RadTab runat="server" Text="Search Results" PageViewID="RadPageView1">
                        </telerik:RadTab>
                        <telerik:RadTab runat="server" Text="Incident Details" PageViewID="RadPageView2">
                        </telerik:RadTab>
                        <telerik:RadTab runat="server" Text="Emergency Response" PageViewID="RadPageView3"
                            Selected="True">
                        </telerik:RadTab>
                        <telerik:RadTab runat="server" Text="Feedback" PageViewID="RadPageView8" Selected="True">
                        </telerik:RadTab>
                        <telerik:RadTab runat="server" Text="Attachments" PageViewID="RadPageView10" Selected="True">
                        </telerik:RadTab>
                    </Tabs>
                </telerik:RadTabStrip>
            </td>
        </tr>
        <tr>
            <td style="vertical-align: top; overflow: auto; vertical-align: top" class="SetMyHeight">
                <%--<div style="display: none">--%>
                <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0" Height="100%"
                    Width="100%">
                    <telerik:RadPageView ID="RadPageView1" runat="server">
                        <telerik:RadGrid ID="rgSearchIncidents" runat="server" AutoGenerateColumns="False"
                            CellSpacing="0" GridLines="None">
                            <ClientSettings>
                                <Selecting AllowRowSelect="True" />
                                <ClientEvents OnCommand="rgSearchIncidents_OnCommand" OnGridCreated="rgSearchIncidents_OnGridCreated"
                                    OnRowDataBound="rgSearchIncidents_OnRowDataBound" />
                            </ClientSettings>
                            <MasterTableView>
                                <CommandItemSettings ExportToPdfText="Export to PDF" />
                                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                    <HeaderStyle Width="20px" />
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                    <HeaderStyle Width="20px" />
                                </ExpandCollapseColumn>
                                <Columns>
                                    <telerik:GridClientSelectColumn FilterControlAltText="Filter column column" HeaderText="#"
                                        UniqueName="column">
                                    </telerik:GridClientSelectColumn>
                                    <telerik:GridBoundColumn DataField="Title" FilterControlAltText="Filter column1 column"
                                        HeaderText="Title" UniqueName="column1">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="VesselName" FilterControlAltText="Filter column2 column"
                                        HeaderText="Vessel" UniqueName="column2">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="FRTime" FilterControlAltText="Filter column3 column"
                                        HeaderText="First Reports Time" UniqueName="column3">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="IncidentType" FilterControlAltText="Filter column4 column"
                                        HeaderText="Type" UniqueName="column4">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="IsClosed" FilterControlAltText="Filter column5 column"
                                        HeaderText="Is Closed" UniqueName="column5">
                                    </telerik:GridBoundColumn>
                                </Columns>
                                <EditFormSettings>
                                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                    </EditColumn>
                                </EditFormSettings>
                            </MasterTableView>
                            <FilterMenu EnableImageSprites="False">
                            </FilterMenu>
                        </telerik:RadGrid>
                    </telerik:RadPageView>
                    <telerik:RadPageView ID="RadPageView2" runat="server">
                        <table>
                            <tr>
                                <td colspan="2" style="text-align: right">
                                    <telerik:RadButton ID="rbtnPrint" runat="server" Text="Print" OnClientClicking="rbtnPrint_OnClientClicking">
                                    </telerik:RadButton>
                                </td>
                            </tr>
                            <tr style="vertical-align: top">
                                <td>
                                    <asp:Label ID="Label5" runat="server" Text="Vessel :" SkinID="ContentLabel"></asp:Label>
                                </td>
                                <td>
                                    <telerik:RadComboBox ID="rcbVessels" runat="server" OnClientLoad="rcbVessels_OnClientLoad">
                                    </telerik:RadComboBox>
                                </td>
                            </tr>
                            <tr style="vertical-align: top">
                                <td>
                                    <asp:Label ID="Label1" runat="server" Text="Title :" SkinID="ContentLabel"></asp:Label>
                                </td>
                                <td>
                                    <telerik:RadTextBox ID="rtbxTitle" runat="server" ClientEvents-OnValueChanged="rtbxTitle_OnvalueChanged">
                                    </telerik:RadTextBox>
                                </td>
                            </tr>
                            <tr style="vertical-align: top">
                                <td>
                                    <asp:Label ID="Label2" runat="server" Text="First Report Time :" SkinID="ContentLabel"></asp:Label>
                                </td>
                                <td>
                                    <telerik:RadDateTimePicker ID="rdtpReportTime" runat="server" Culture="en-SG">
                                        <TimeView CellSpacing="-1" Columns="4" Culture="en-SG" Interval="00:30:00" TimeFormat="HH:mm">
                                        </TimeView>
                                        <TimePopupButton HoverImageUrl="" ImageUrl="" />
                                        <Calendar UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x">
                                        </Calendar>
                                        <DateInput DateFormat="d/M/yyyy" DisplayDateFormat="d/M/yyyy" DisplayText="" LabelWidth="40%"
                                            type="text" value="">
                                        </DateInput>
                                        <DatePopupButton HoverImageUrl="" ImageUrl="" />
                                    </telerik:RadDateTimePicker>
                                </td>
                            </tr>
                            <tr style="vertical-align: top">
                                <td>
                                    <asp:Label ID="Label3" runat="server" Text="Incident Type :" SkinID="ContentLabel"></asp:Label>
                                </td>
                                <td>
                                    <asp:RadioButtonList ID="rblIncidentType" runat="server" RepeatDirection="Horizontal">
                                        <asp:ListItem Text="Real Incident" Value="true"></asp:ListItem>
                                        <asp:ListItem Text="Drill" Value="false"></asp:ListItem>
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr style="vertical-align: top">
                                <td>
                                    <asp:Label ID="Label4" runat="server" Text="Is Closed :" SkinID="ContentLabel"></asp:Label>
                                </td>
                                <td>
                                    <asp:Label ID="lblIsClosed" runat="server" Text=""></asp:Label>
                                    <%--<asp:CheckBox ID="cbClosed" runat="server" onclick="javaScript:return checkIncidentClose();" />--%>
                                </td>
                            </tr>
                        </table>
                        <asp:HiddenField ID="hfCloseComment" runat="server" />
                    </telerik:RadPageView>
                    <telerik:RadPageView ID="RadPageView3" runat="server" CssClass="AutoHeight">
                        <table style="height: 95%; width: 95%; vertical-align: top">
                            <tr>
                                <td colspan="2" style="height: 30px; text-align: center; color: Red;">
                                    <h4>
                                        <span id='timer'></span>
                                    </h4>
                                </td>
                            </tr>
                            <tr>
                                <td style="height: 100%; width: 100%">
                                    <table style="height: 100%; width: 100%">
                                        <tr>
                                            <td>
                                                <telerik:RadTabStrip ID="RadTabStrip1" runat="server" MultiPageID="RadMultiPage2"
                                                    SelectedIndex="0">
                                                    <Tabs>
                                                        <telerik:RadTab runat="server" Text="Vessel Information" PageViewID="RadPageView4">
                                                        </telerik:RadTab>
                                                        <telerik:RadTab runat="server" Text="General Information" PageViewID="RadPageView5">
                                                        </telerik:RadTab>
                                                        <telerik:RadTab runat="server" Text="Status Board" PageViewID="RadPageView6" Selected="True">
                                                        </telerik:RadTab>
                                                        <telerik:RadTab runat="server" Text="Scribe" PageViewID="RadPageView7" Selected="True">
                                                        </telerik:RadTab>
                                                        <telerik:RadTab runat="server" Text="Chat" PageViewID="RadPageView9" Selected="True">
                                                        </telerik:RadTab>
                                                    </Tabs>
                                                </telerik:RadTabStrip>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <telerik:RadMultiPage ID="RadMultiPage2" runat="server" SelectedIndex="0">
                                                    <telerik:RadPageView ID="RadPageView4" runat="server" Width="100%">
                                                        <table style="width: 100%">
                                                            <tr>
                                                                <td style="text-align: center">
                                                                    <telerik:RadButton ID="rbtnContacts" runat="server" Text="Contacts" Width="200px"
                                                                        OnClientClicking="rbtnContacts_OnClientClicking">
                                                                    </telerik:RadButton>
                                                                </td>
                                                                <td style="text-align: center">
                                                                    <telerik:RadButton ID="RadButton5" runat="server" Text="Documents" Width="200px"
                                                                        Enabled="false">
                                                                    </telerik:RadButton>
                                                                </td>
                                                                <td style="text-align: center">
                                                                    <telerik:RadButton ID="rbtCrewList" runat="server" Text="Crew List" Width="200px"
                                                                        OnClientClicking="rbtCrewList_OnClientClicking">
                                                                    </telerik:RadButton>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="3">
                                                                    <div id="VesselContent" style="width: 100%; min-height: 500px; overflow: auto">
                                                                    </div>
                                                                    <table id="VesselContent2">
                                                                    </table>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </telerik:RadPageView>
                                                    <telerik:RadPageView ID="RadPageView5" runat="server" Width="100%">
                                                        <table style="width: 100%">
                                                            <tr>
                                                                <td style="text-align: center">
                                                                    <telerik:RadButton ID="rbtnERTeamContacts" runat="server" Text="Response Team Contacts"
                                                                        Width="200px" OnClientClicking="rbtnERTeamContacts_OnClientClicking">
                                                                    </telerik:RadButton>
                                                                </td>
                                                                <td style="text-align: center">
                                                                    <telerik:RadButton ID="rbtnEquipProc" runat="server" Text="ER Equipment Procedures"
                                                                        OnClientClicking="rbtnEquipProc_OnClientClicking" Width="200px">
                                                                    </telerik:RadButton>
                                                                </td>
                                                                <td style="text-align: center">
                                                                    <telerik:RadButton ID="RadButton3" runat="server" Text="Material Location" Width="200px"
                                                                        Enabled="false">
                                                                    </telerik:RadButton>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="3">
                                                                    <table id="GeneralInfo">
                                                                    </table>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </telerik:RadPageView>
                                                    <telerik:RadPageView ID="RadPageView6" runat="server" Width="100%">
                                                        <div style="width: 100%; overflow: auto">
                                                            <table id='statusBoardItems'>
                                                            </table>
                                                        </div>
                                                    </telerik:RadPageView>
                                                    <telerik:RadPageView ID="RadPageView7" runat="server" Width="100%">
                                                        <uc1:Scribe ID="Scribe1" runat="server" />
                                                    </telerik:RadPageView>
                                                    <telerik:RadPageView ID="RadPageView9" runat="server" Width="100%">
                                                        <uc3:EmergencyChat ID="EmergencyChat1" runat="server" />
                                                    </telerik:RadPageView>
                                                </telerik:RadMultiPage>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </telerik:RadPageView>
                    <telerik:RadPageView ID="RadPageView8" runat="server" CssClass="AutoHeight">
                        <table style="height: 95%; width: 95%; vertical-align: top">
                            <tr>
                                <td style="width: 250px">
                                    <asp:Label ID="Label23" runat="server" Text="Add new feedback : " SkinID="ContentLabel"></asp:Label>
                                </td>
                                <td>
                                    <asp:ImageButton ID="imgBtnAddPlannedJob" runat="server" ImageAlign="Middle" ImageUrl="~/Images/Add_Plus.png"
                                        AlternateText="New feedback" OnClientClick="return loadAddFeedBackWindow()" />
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:Label ID="Label6" runat="server" Text="Existing feedback : " SkinID="ContentLabel"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="Label7" runat="server" Text="Feedback type : " SkinID="ContentText"></asp:Label>
                                </td>
                                <td>
                                    <telerik:RadComboBox ID="rcbFeedbackType" runat="server" OnClientSelectedIndexChanged="rcbFeedbackType_OnClientSelectedIndexChanged">
                                        <Items>
                                            <telerik:RadComboBoxItem Text="All" Selected="true" />
                                            <telerik:RadComboBoxItem Text="Positives" />
                                            <telerik:RadComboBoxItem Text="Corrective Actions" />
                                        </Items>
                                    </telerik:RadComboBox>
                                    &nbsp;&nbsp;<telerik:RadButton ID="btnsApprove" runat="server" Text="Submit Feedback"
                                        OnClientClicking="btnsApprove_OnClientClicking">
                                    </telerik:RadButton>
                                    &nbsp;&nbsp;
                                    <telerik:RadButton ID="rbtnPrintFeedback" runat="server" Text="Print" OnClientClicking="rbtnPrintFeedback_OnClientClicking">
                                    </telerik:RadButton>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <telerik:RadGrid ID="rgFeedbacks" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                                        CellSpacing="0" GridLines="None">
                                        <ClientSettings>
                                            <Selecting AllowRowSelect="True" />
                                            <ClientEvents OnCommand="rgFeedbacks_OnCommand" OnGridCreated="rgFeedbacks_OnGridCreated"
                                                OnRowDataBound="rgFeedbacks_OnRowDataBound" />
                                        </ClientSettings>
                                        <MasterTableView>
                                            <CommandItemSettings ExportToPdfText="Export to PDF" />
                                            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                                <HeaderStyle Width="20px" />
                                            </RowIndicatorColumn>
                                            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                                <HeaderStyle Width="20px" />
                                            </ExpandCollapseColumn>
                                            <Columns>
                                                <telerik:GridClientSelectColumn FilterControlAltText="Filter column column" HeaderText="#"
                                                    UniqueName="column">
                                                </telerik:GridClientSelectColumn>
                                                <telerik:GridBoundColumn FilterControlAltText="Filter column1 column" HeaderText="Feedback"
                                                    UniqueName="column1" DataField="FeedbackComments">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn FilterControlAltText="Filter column2 column" HeaderText="Type"
                                                    UniqueName="column2" DataField="FeedbackType">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn FilterControlAltText="Filter column3 column" HeaderText="CAR Description"
                                                    UniqueName="column3" DataField="CorrectiveActionDescription">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn FilterControlAltText="Filter column4 column" HeaderText="Assigned to"
                                                    UniqueName="column4" DataField="AssignedUser">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn FilterControlAltText="Filter column5 column" HeaderText="Review by"
                                                    UniqueName="column5" DataField="ReviewUser">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn FilterControlAltText="Filter column6 column" HeaderText="Expected Date"
                                                    UniqueName="column6" DataField="ExpectedDate">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn FilterControlAltText="Filter column7 column" HeaderText="Created By"
                                                    UniqueName="column7" DataField="CreatedUser">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn FilterControlAltText="Filter column8 column" HeaderText="Created Date"
                                                    UniqueName="column8" DataField="CreatedDate">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn FilterControlAltText="Filter column9 column" HeaderText="Status"
                                                    UniqueName="column9" DataField="Status">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn FilterControlAltText="Filter column10 column" HeaderText="Action Track Status"
                                                    UniqueName="column10" DataField="CorrectiveActionLink">
                                                </telerik:GridBoundColumn>
                                            </Columns>
                                            <EditFormSettings>
                                                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                </EditColumn>
                                            </EditFormSettings>
                                        </MasterTableView>
                                        <FilterMenu EnableImageSprites="False">
                                        </FilterMenu>
                                    </telerik:RadGrid>
                                </td>
                            </tr>
                        </table>
                    </telerik:RadPageView>
                    <telerik:RadPageView ID="RadPageView10" runat="server" CssClass="AutoHeight">
                        <cc1:OmniFileUploader ID="OmniFileUploader1" runat="server" TargetFolder="~/TempFiles"
                            OnFileUploading="OmniFileUploader_OnFileUploading" OnFilesUploaded="OmniFileUploader_OnFilesUploaded"
                            OnGetData="OmniFileUploader_OnGetData" />
                    </telerik:RadPageView>
                </telerik:RadMultiPage>
            </td>
        </tr>
    </table>
    <telerik:RadWindow ID="rwShowHistory" runat="server" Modal="false" Height="418px"
        Width="600px" BackColor="#f5e6f034" Title="Status History" ShowContentDuringLoad="false"
        Behaviors="Resize, Close, Move, Reload" VisibleStatusbar="false">
    </telerik:RadWindow>
    <telerik:RadWindow ID="rwFeedback" runat="server" Modal="true" Height="418px" Width="600px"
        BackColor="#f5e6f034" Title="Feedback" ShowContentDuringLoad="false" Behaviors="Resize, Close, Move, Reload"
        VisibleStatusbar="false" OnClientClose="rwFeedback_OnClientClose">
    </telerik:RadWindow>
    <script type="text/javascript">

        function initERObject() {
            var erObject = new ERMgmt();
            erObject.CloseCommentCtrl = $get('<%=hfCloseComment.ClientID %>');
            erObject.CloseCtrl = $get('<%=lblIsClosed.ClientID %>');
            erObject.ERTabStrip = $find('<%=rtsERManagement.ClientID %>');
            erObject.FirstReportCtrl = $find('<%=rdtpReportTime.ClientID %>');
            erObject.IncedentTypeCtrl = $get('<%=rblIncidentType.ClientID %>');
            erObject.TitleCtrl = $find('<%=rtbxTitle.ClientID %>');
            erObject.SearchGrid = $find('<%=rgSearchIncidents.ClientID %>');
            erObject.VesselCtrl = $find('<%=rcbVessels.ClientID %>');
            erObject.FileUploader = $get('<%=OmniFileUploader1.ClientID %>');
            erObject.FeedbackFilter = $find('<%=rcbFeedbackType.ClientID %>');
            erObject.FeedbackGrid = $find('<%=rgFeedbacks.ClientID %>');

            return erObject;
        }

        function rgSearchIncidents_OnCommand(sender, args) {
            switch (args.get_commandName()) {
                case 'Page':
                    {
                        var erObject = new ERMgmt();
                        erObject.SearchIncidenets();
                        break;
                    }
            }
            args.set_cancel(true);
        }

        function rgSearchIncidents_OnGridCreated(sender, args) {
            sender.get_masterTableView().set_dataSource('');
            sender.get_masterTableView().dataBind();
        }

        function rgFeedbacks_OnCommand(sender, args) {
            switch (args.get_commandName()) {
                case 'Page':
                    {
                        var erObject = new initERObject();
                        erObject.LoadIncidenetFeedback();
                        break;
                    }
            }
            args.set_cancel(true);
        }

        function rgFeedbacks_OnGridCreated(sender, args) {
            sender.get_masterTableView().set_dataSource('');
            sender.get_masterTableView().dataBind();
        }

        function rgFeedbacks_OnRowDataBound(sender, args) {
            var cell = args.get_item().get_cell('column1');
            var anchor = String.format("<a href='#' onclick='return showFeedbackDetails({0});'>{1}</a>", String.format("\"{0}\"", args.get_dataItem().ID), args.get_dataItem().FeedbackComments);
            cell.innerHTML = anchor;

            cell = args.get_item().get_cell('column6');
            cell.innerHTML = MASTER_DateToString(args.get_dataItem().ExpectedDate);

            cell = args.get_item().get_cell('column8');
            cell.innerHTML = MASTER_DateToString(args.get_dataItem().ExpectedDate);
        }

        function showFeedbackDetails(fbID) {
            var url = '<%=Page.ResolveClientUrl("~/Internal/InternalWindows.aspx") %>';
            url += '?ctrl=EMFB&ICode=' + MASTER_GetCurrentBusinessObject().ID + '&FBID=' + fbID;

            $find('<%=rwFeedback.ClientID %>').setUrl(url);
            $find('<%=rwFeedback.ClientID %>').show();
            return false;
        }

        function rwFeedback_OnClientClose(sender, args) {
            var erObject = initERObject();
            erObject.LoadIncidenetFeedback();
        }

        function rcbFeedbackType_OnClientSelectedIndexChanged(sender, args) {
            var erObject = initERObject();
            Landscape.EmergencyActions.GetFeedbackList(MASTER_GetCurrentBusinessObject().ID, erObject.FeedbackFilter.get_text(), 0, 10, function (result, e) {
                e.FeedbackGrid.get_masterTableView().set_dataSource(result);
                e.FeedbackGrid.get_masterTableView().dataBind();
            }, function (result, e) { N_NotifyMessage('Error !!!', result.get_message(), 2); }, erObject);
        }

        function checkIncidentClose() {
            var incObj = initERObject();
            if (incObj.CloseCtrl.checked) {
                N_ConfirmMessage('Confirm !!!', 'Do you really want to close this incident.', 3, proceedToClose, donotClose);
            }
        }

        function rbtnERTeamContacts_OnClientClicking(sender, args) {
            var fldrPath = '<%=ERMManualLocation %>';
            var markup = "<tr><td style='vertical-align:top'>${SNo}.</td><td style='width:500px; vertical-align:top'><a href='#' onclick='return downloadFile(\"${DCTMID}\")'>${FileName}</a></td></tr>";
            $.template("ert_contacts", markup);
            $('#GeneralInfo').empty();

            $('#GeneralInfo').append("<tr><th style='vertical-align:top'>S.No. </th><th>File Name</th></tr>");

            var strArray = new Array();
            strArray.push('ERT Contact Details');

            Landscape.MaintenanceActions.GetFilesIn(fldrPath, strArray, function (result, e) {
                $.tmpl('ert_contacts', result).appendTo('#GeneralInfo');
            }, function (result, e) { N_NotifyMessage('Error !!!', result.get_message(), 2); });

            args.set_cancel(true);
        }

        function rbtnContacts_OnClientClicking(sender, args) {
            var fldrPath = '<%=ERMManualLocation %>';
            var markup = "<tr><td style='vertical-align:top'>${SNo}.</td><td style='width:500px; vertical-align:top'><a href='#' onclick='return downloadFile(\"${DCTMID}\")'>${FileName}</a></td></tr>";
            $.template("vsl_contacts", markup);
            $('#VesselContent2').css('display', 'block');
            $('#VesselContent').css('display', 'none');
            $('#VesselContent2').empty();

            $('#VesselContent2').append("<tr><th style='vertical-align:top'>S.No. </th><th>File Name</th></tr>");

            var strArray = new Array();
            strArray.push('CONTACT DETAILS-FSO ' + MASTER_GetCurrentBusinessObject().VesselShortName);
            strArray.push('External contact details');

            Landscape.MaintenanceActions.GetFilesIn(fldrPath, strArray, function (result, e) {
                $.tmpl('vsl_contacts', result).appendTo('#VesselContent2');
            }, function (result, e) { N_NotifyMessage('Error !!!', result.get_message(), 2); });

            args.set_cancel(true);
        }

        function proceedToClose() {
            N_NotifyForComments('Closing Comments !!!', '', 3, function (input) { closeIncident(input); });
        }

        function closeIncident(input) {
            var incObj = initERObject();
            incObj.CloseIncident(input);
        }

        function donotClose() {
            var incObj = initERObject();
            incObj.CloseCtrl.checked = false;
        }

        function rbtnEquipProc_OnClientClicking(result, args) {
            var fldrPath = '<%=ProductManualLocation %>';
            var markup = "<tr><td style='vertical-align:top'>${SNo}.</td><td style='width:500px; vertical-align:top'><a href='#' onclick='return downloadFile(\"${DCTMID}\")'>${FileName}</a></td></tr>";
            $.template("procedures", markup);
            $('#GeneralInfo').empty();

            $('#GeneralInfo').append("<tr><th style='vertical-align:top'>S.No. </th><th>File Name</th></tr>");

            Landscape.MaintenanceActions.GetFilesIn(fldrPath, null, function (result, e) {
                $.tmpl('procedures', result).appendTo('#GeneralInfo');
            }, function (result, e) { N_NotifyMessage('Error !!!', result.get_message(), 2); });

            args.set_cancel(true);
        }

        function downloadFile(dctmID) {
            var htmlScr = '<iframe src=\"{0}?DocID={1}\" style=\"height:0px; width:0px\"></iframe>';
            htmlScr = String.format(htmlScr, '<%=Page.ResolveClientUrl("~/FileDownloader.aspx") %>', dctmID);

            N_NotifyMessage('Downloading !!!', 'Downloading file, please wait till you get notified. Do not close this dialogue box till dowloading finished.' + htmlScr, 3);
            return false;
        }

        function rbtCrewList_OnClientClicking(sender, args) {

            var erMngr = initERObject();

            Landscape.AdministrativeActions.GetVesselByCode(erMngr.VesselCtrl.get_value(), function (result, e) {
                var url = String.format("<iframe src='http://omniwebserve3/compastpot/crewlist.ASP?vslcode={0}' style='height:100%; width:100%' />", result.RecordNum);

                $('#VesselContent').css('display', 'block');
                $('#VesselContent2').css('display', 'none');
                $('#VesselContent').empty();
                $('#VesselContent').html(url);
            }, function (result, e) { N_NotifyMessage('Error !!!', result.get_message(), 2); });
            args.set_cancel(true);
        }

        function rgSearchIncidents_OnRowDataBound(sender, args) {
            var cell = args.get_item().get_cell('column1');
            var anchor = String.format("<a href='#' onclick='return showIncidentDetails({0});'>{1}</a>", String.format("\"{0}\"", args.get_dataItem().ID), args.get_dataItem().Title);
            cell.innerHTML = anchor;

            var cell1 = args.get_item().get_cell('column4');
            cell1.innerHTML = 'Drill';
            if (args.get_dataItem().IsIncident)
                cell1.innerHTML = 'Incident';

            var cell2 = args.get_item().get_cell('column5');
            cell2.innerHTML = 'No';
            if (args.get_dataItem().IsClosed)
                cell2.innerHTML = 'Yes';
        }

        function showIncidentDetails(pIncCode) {
            var erMngr = initERObject();
            erMngr.LoadIncidentDetails(pIncCode);
            loadStatusItems();
        }

        function rtbModuleActions_OnClientButtonClicked(sender, args) {
            processCommands(args.get_item().get_commandName());
            args.get_item().set_checked(false);
        }

        function rtbxTitle_OnvalueChanged(sender, args) {
            //TODO
            //Check for duplication

        }

        function processCommands(pCmdName) {
            switch (pCmdName) {
                case 'SAVE':
                    {
                        var erMngr = initERObject();
                        if (MASTER_GetCurrentBusinessObject() != null || erMngr.TitleCtrl.get_value().trim() != '') {
                            if (GLOBAL_CheckUserHasPrivilege('EDIT')) {
                                erMngr.SaveIncident();
                            } else {
                                N_NotifyMessage('Security', 'You don\'t have the permission to perfom this operation.', 3);
                            }
                        }
                        else {
                            N_NotifyMessage('Invalid', 'Please create or select the incident for save operation.', 3);
                        }

                        break;
                    }

                case 'LIST':
                    {
                        if (GLOBAL_CheckUserHasPrivilege('SEARCH')) {
                            var erMngr = initERObject();
                            erMngr.SearchIncidenets();
                            erMngr.SelectTabByIndex(0);
                        } else {
                            N_NotifyMessage('Security', 'You don\'t have the permission to perfom this operation.', 3);
                        }

                        break;
                    }

                case 'DELETE':
                    {
                        if (MASTER_GetCurrentBusinessObject() != null) {
                            if (GLOBAL_CheckUserHasPrivilege('DELETE')) {
                                //performDelete();
                            } else {
                                N_NotifyMessage('Security', 'You don\'t have the permission to perfom this operation.', 3);
                            }
                        }
                        else {
                            N_NotifyMessage('Invalid', 'Please create or select the incident for save operation.', 3);
                        }
                        break;
                    }

                case 'NEW':
                    {
                        if (GLOBAL_CheckUserHasPrivilege('EDIT')) {
                            var erMngr = initERObject();
                            erMngr.SelectTabByIndex(1);
                            MASTER_StoreCurrentBusinessObject(null);
                            clearEMChat();
                            clearScribe();
                            erMngr.ClearCtrls();
                        } else {
                            N_NotifyMessage('Security', 'You don\'t have the permission to perfom this operation.', 3);
                        }
                        break;
                    }

                case 'PRINT':
                    {
                        if (MASTER_GetCurrentBusinessObject() != null) {
                            if (GLOBAL_CheckUserHasPrivilege('PRINT')) {
                                var erMngr = initERObject();
                                if (erMngr.GetActiveTabIndex() == 3) {
                                    //Feedback
                                    var url = "PrintFeedback.aspx?ICode=" + MASTER_GetCurrentBusinessObject().ID;
                                    window.open(url);
                                }
                            } else {
                                N_NotifyMessage('Security', 'You don\'t have the permission to perfom this operation.', 3);
                            }
                        }
                        else {
                            N_NotifyMessage('Invalid', 'Please create or select the incident for print operation.', 3);
                        }

                        break;
                    }
            }
        }

        function rbtnPrint_OnClientClicking(sender, args) {
            if (MASTER_GetCurrentBusinessObject() != null) {
                if (GLOBAL_CheckUserHasPrivilege('PRINT')) {
                    var erMngr = initERObject();
                    var url = "../OmniReports.aspx?RPTID=IDET&INCID=" + MASTER_GetCurrentBusinessObject().ID;
                    window.open(url);
                } else {
                    N_NotifyMessage('Security', 'You don\'t have the permission to perfom this operation.', 3);
                }
            }
            else {
                N_NotifyMessage('Invalid', 'Please create or select the incident for print operation.', 3);
            }

            args.set_cancel(true);
        }

        function rbtnPrintFeedback_OnClientClicking(sender, args) {
            if (MASTER_GetCurrentBusinessObject() != null) {
                if (GLOBAL_CheckUserHasPrivilege('PRINT')) {
                    var erMngr = initERObject();
                    var url = "../OmniReports.aspx?RPTID=FEED&INCID=" + MASTER_GetCurrentBusinessObject().ID;
                    window.open(url);
                } else {
                    N_NotifyMessage('Security', 'You don\'t have the permission to perfom this operation.', 3);
                }
            }
            else {
                N_NotifyMessage('Invalid', 'Please create or select the incident for print operation.', 3);
            }

            args.set_cancel(true);
        }

        function rcbVessels_OnClientLoad(sender, args) {
            var erObject = initERObject();
            erObject.LoadVessels();
        }

        function showTimer() {
            if (MASTER_GetCurrentBusinessObject() != null) {
                var erObject = initERObject();
                if (!MASTER_GetCurrentBusinessObject().IsClosed) {
                    var frTime = erObject.FirstReportCtrl.get_selectedDate();
                    var timeDelta = (new Date()) - frTime;

                    timeDelta = timeDelta / 1000;
                    var days = Math.floor(timeDelta / 86400);
                    var hours = Math.floor(timeDelta / 3600) % 24;
                    var minutes = Math.floor(timeDelta / 60) % 60;
                    var seconds = timeDelta % 60;

                    hours = (hours < 10 ? '0' + hours : hours);
                    minutes = (minutes < 10 ? '0' + minutes : minutes);
                    seconds = seconds.toFixed();

                    var fullString = 'Time Since First Report : {0}D {1}H {2}M {3}S'
                    $('#timer').html(String.format(fullString, days, hours, minutes, (seconds < 10 ? '0' + seconds : seconds)));
                }
                else {
                    $('#timer').html('This incident is closed.');
                }
            }
        }

        function loadStatusItems() {
            var markup = "<tr><td style='vertical-align:top'><span class='StatusTitle'>${Sequence}.</span> </td><td style='width:500px; vertical-align:top'><span  class='StatusTitle'>{{html Title}}</span></td><td><textarea id='remarks_${Sequence}' rows='2' cols='40'></textarea></td><td><input id='btnsave_${Sequence}' type='button' value='Save' onClick='saveStatus(remarks_${Sequence}, \"${ID}\", \"${ShortName}\")' /><input id='btnHistory_${Sequence}' type='button' value='History' onClick='showHistory(\"${ID}\")' /></td></tr>";
            $.template("statusBoard", markup);
            $('#statusBoardItems').empty();

            Landscape.EmergencyActions.GetStatusBoardItemsByTitle('', 0, -1, function (result, e) {
                $.tmpl('statusBoard', result).appendTo('#statusBoardItems');
            }, function (result, e) { N_NotifyMessage('Error !!!', result.get_message(), 2); });
        }

        function saveStatus(ctrl, guid, shortName) {
            if (MASTER_GetCurrentBusinessObject() != null) {
                var erObject = initERObject();
                if (ctrl.value.trim() != '' && !MASTER_GetCurrentBusinessObject().IsClosed) {
                    erObject.SaveStatusUpdate(guid, ctrl.value.replace(/\n/g, '<br/>'), shortName);
                    //MASTER_ShowNotification(ctrl.value);
                }
                else {
                    N_NotifyMessage('Incident Closed !!!', 'The selected incident is already closed. Further updates cannot be saved.', 2);
                }
            }
            else {
                N_NotifyMessage('Invalid', 'Please create or select the incident for save operation.', 3);
            }
        }

        function showHistory(guid) {
            if (MASTER_GetCurrentBusinessObject() != null) {
                var url = '<%=Page.ResolveClientUrl("~/Internal/InternalWindows.aspx") %>';
                url += '?ctrl=EMSEH&ICode=' + MASTER_GetCurrentBusinessObject().ID + '&SICode=' + guid;

                $find('<%=rwShowHistory.ClientID %>').setUrl(url);
                $find('<%=rwShowHistory.ClientID %>').show();
            }
            else {
                N_NotifyMessage('Invalid', 'Please create or select the incident for save operation.', 3);
            }
        }

        function canUploadFiles() {
            if (MASTER_GetCurrentBusinessObject() != null) {
                if (MASTER_GetCurrentBusinessObject().IsClosed) {
                    N_NotifyMessage('Closed !!!', 'The current incident is closed. Cannot upload or delete files.', 2);
                }

                return !MASTER_GetCurrentBusinessObject().IsClosed;
            }
            else {
                N_NotifyMessage('Invalid', 'Please create or select the incident for save operation.', 3);
                return false;
            }
        }

        function OmniFileUploader_OnGetData(pEntityID, pPageNo, pPageSize) {
            Landscape.EmergencyActions.GetFilesForIncident(pEntityID, pPageNo, pPageSize, function (result, e) {
                var erMngr = initERObject();
                erMngr.FileUploader.BindFileList(result);
            }, function (result, e) { N_NotifyMessage('Error !!!', result.get_message(), 2); });
        }

        function loadAddFeedBackWindow() {
            if (MASTER_GetCurrentBusinessObject() != null) {
                if (!MASTER_GetCurrentBusinessObject().IsClosed) {
                    var url = '<%=Page.ResolveClientUrl("~/Internal/InternalWindows.aspx") %>';
                    url += '?ctrl=EMFB&ICode=' + MASTER_GetCurrentBusinessObject().ID;

                    $find('<%=rwFeedback.ClientID %>').setUrl(url);
                    $find('<%=rwFeedback.ClientID %>').show();
                }
                else {
                    N_NotifyMessage('Incident Closed', 'The selected incident closed. No further feedback is allowed.', 2);
                }
            }
            else {
                N_NotifyMessage('Invalid', 'Please create or select the incident for save operation.', 3);
            }
            return false;
        }

        function OmniFileUploader_OnFileUploading(sender, args) {
            if (!canUploadFiles()) {
                args.set_cancel(true);
            }
        }

        function OmniFileUploader_OnFilesUploaded(sender, args) {
            //$get('<%=OmniFileUploader1.ClientID %>').LoadFiles(MASTER_GetCurrentBusinessObject().ID);
        }

        function btnsApprove_OnClientClicking(sender, args) {
            if (MASTER_GetCurrentBusinessObject() != null) {
                var msg = "Submit feedback will freeze the feedback from further changes.";
                msg += " This also creates the corrective actions if required in the system.";
                msg += " The current incident will be closed and this is an irreversable action.";
                msg += " Do you want to proceed?";
                N_ConfirmMessage('Submit Feedback', msg, 3, proceedToSubmit, null);
            }
            else {
                //->
            }
            args.set_cancel(true);
        }

        function proceedToSubmit() {
            Landscape.EmergencyActions.SubmitFeedbackAndClose(MASTER_GetCurrentBusinessObject().ID, MASTER_GetCurrentUserCode(), function (result, e) {
                N_NotifyMessage('Submited', 'All the feedback was submited successfuly. The current incident is closed. If the feedback has any corrective actions then please proceed to Action Track & Management module to finalize them.', 1);

                var bizObject = MASTER_GetCurrentBusinessObject();
                bizObject.IsClosed = true;

                MASTER_StoreCurrentBusinessObject(bizObject);

                $.connection.hub.stop();

                var erMngr = initERObject();
                erMngr.CloseCtrl.value = 'Yes';

                rwFeedback_OnClientClose(null, null);

            }, function (result, e) { N_NotifyMessage('Error !!!', result.get_message(), 2); });
        }

        function ToggleModuleActions(pActionIndex, pShow) {
            var moduleActionCtrl = $find('<%=rtbModuleActions.ClientID %>');
            moduleActionCtrl.get_allItems()[pActionIndex].set_visible(pShow);
        }

        function rtsERManagement_OnClientTabSelecting(sender, args) {
            switch (args.get_tab().get_index()) {
                case 0: //Search tab
                    {
                        //Show
                        ToggleModuleActions(0, true); //Search
                        ToggleModuleActions(1, true); //New

                        //Hide
                        ToggleModuleActions(2, false); //Save
                        ToggleModuleActions(3, false); //Delete
                        break;
                    }

                case 1: //Details tab
                    {
                        //Show
                        ToggleModuleActions(0, true); //Search
                        ToggleModuleActions(1, true); //New
                        ToggleModuleActions(2, true); //Save
                        ToggleModuleActions(3, true); //Delete
                        

                        //Hide


                        break;
                    }

                case 2: //Emergency Response
                    {
                        //Show
                        ToggleModuleActions(0, true); //Search

                        //Hide
                        ToggleModuleActions(1, false); //New
                        ToggleModuleActions(2, false); //Save
                        ToggleModuleActions(3, false); //Delete

                        break;
                    }

                case 3: //Feedback
                    {
                        //Show
                        ToggleModuleActions(0, true); //Search

                        //Hide
                        ToggleModuleActions(1, false); //New
                        ToggleModuleActions(2, false); //Save
                        ToggleModuleActions(3, false); //Delete

                        break;
                    }

                case 4: //Attachments
                    {
                        //Show
                        ToggleModuleActions(0, true); //Search
                        ToggleModuleActions(2, true); //Save

                        //Hide
                        ToggleModuleActions(1, false); //New
                        ToggleModuleActions(3, false); //Delete

                        break;
                    }
            }
        }

    </script>
</asp:Content>
